
import * as cc from "cc";
import { UIWindowBase } from '../../../framework/ui/UIWindowBase';
import { VMCenter } from '../../../framework/vm/VMCenter';
import { VMEntity } from '../../../framework/vm/VMEntity';
const { ccclass } = cc._decorator;
/**
 * Predefined variables
 * Name = RenameWindow
 * DateTime = Sun Mar 20 2022 15:04:34 GMT+0800 (中国标准时间)
 * Author = 272493431
 * FileBasename = RenameWindow.ts
 * FileBasenameNoExtension = RenameWindow
 * URL = db://assets/scripts/scene/VMDemo/windows/RenameWindow.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('RenameWindow')
export class RenameWindow extends UIWindowBase implements IMVVM{
    _vmTag: string;
    _vmEntitys: VMEntity[];

    constructor(){
        super();
        this.onCtor("prefabs/RenameWindow");
    }

    onLoaded(): void {
        this.onActive();
        let self = this;
        // VMCenter.
        let editbox = this.findComponent("editbox",cc.EditBox);
        let buttonOk = this.find(">buttonOk");
        let buttonCancel = this.find(">buttonCancel");
        let labelName = this.find("labelName");
        
        VMCenter.Label(this,labelName,{watchPath: "player.name"});

        VMCenter.ButtonClick(this,buttonOk,{watchPath: "player.name",operation(opts){
            self.close(); 
            return !!editbox.string ? editbox.string : opts.currentValue;
        }});

        
        VMCenter.ButtonClick(this,buttonCancel,{watchPath: "player.name",operation(opts){
            self.close(); 
            return opts.currentValue;
        }});

      
    }

    onUnloaded(): void {
        this.onFreeze();
        VMCenter.remove(this);
    }

}
